(library (statistics)
  (export percentage
          stat-learned)
  (import (except (rnrs base))
          (only (guile)
                lambda* λ
                exact->inexact)
          (only (vocabulary-filters)
                learned?)
          (model)
          (srfi srfi-43))

  (define percentage
    (lambda* (ratio #:key (precision 2))
      (let ([precision-factor (expt 10 precision)])
        (exact->inexact
         (/ (floor (* (* ratio 100) precision-factor))
            precision-factor)))))

  (define stat-learned
    (λ (vocabulary)
      (/ (vector-count (λ (_ word) (learned? word))
                       (vocabulary-words vocabulary))
         (vector-length (vocabulary-words vocabulary))))))
